{{extend '../_layouts/home.html'}}


{{block 'title'}}{{'多人博客 - 首页'}}{{/block}}

{{block 'body'}}
<section class="container">
  <!-- {{include '../_partials/settings-nav.html'}} -->
  <div class="col-md-3 list-group">
    <a href="#" class="list-group-item disabled">用户设置</a>
    <a href="/settings/profile" class="list-group-item active">基本信息</a>
    <a href="/settings/admin" class="list-group-item ">账户设置</a>
  </div>
  <div class="col-md-5">
    <form id="profile_form">
      <div class="form-group">
        <label for="exampleInputEmail1">账号</label>
        <input type="text" class="form-control" name="email" value="{{user.email}}" readonly>
      </div>
      <div class="form-group">
        <label for="exampleInputPassword1">密码</label>
        <input type="text" class="form-control" id="exampleInputPassword1" value="{{user.password}}" name="password"
          readonly>
      </div>
      <div class="form-group">
        <label for="exampleInputPassword1">昵称</label>
        <input type="text" class="form-control" name="nickname" value="{{user.nickname}}">
      </div>
      <div class="form-group">
        <label for="exampleInputPassword1">介绍</label>
        <input type="textarea" style="height: 102px" class="form-control" name="bio" value="{{user.bio}}">

        <!-- <textarea class="form-control" rows="3" name="bio" value="{{user.bio}}"></textarea> -->
      </div>
      <div class="form-group">
        <label for="exampleInputPassword1">性别</label>
        <div>
          <label class="radio-inline">
            <input type="radio" name="gender" id="inlineRadio1" value="1"> 男
          </label>
          <label class="radio-inline">
            <input type="radio" name="gender" id="inlineRadio2" value="0"> 女
          </label>
          <label class="radio-inline">
            <input type="radio" name="gender" id="inlineRadio3" value="-1"> 保密
          </label>
        </div>
      </div>
      <div class="form-group">
        <label for="exampleInputPassword1">生日</label>
        <input type="text" class="form-control" value="{{user.birthday}}" name="birthday">
      </div>
      <button type="submit" class="btn btn-success">保存</button>
      <a href="/" class="btn btn-danger">取消</a>
    </form>
  </div>
  <div class="col-md-2 profile-avatar">
    <dl>
      <dt>头像设置</dt>
      <dd>
        <img class="avatar" width="150" height="150" src="../public/img/avatar-max-img.png" alt="">
        <div>
          <button class="btn btn-default" href="">Upload new picture</button>
        </div>
      </dd>
    </dl>
  </div>
</section>

{{/block}}
{{block 'script'}}

<script>
  $('#profile_form').on('submit', function (e) {
    e.preventDefault()
    let formData = $(this).serialize()
    // console.log(formData)
    $.ajax({
      url: '/settings/profile',
      type: 'POST',
      data: formData,
      dataType: 'json',
      success: function (data) {
        var err_code = data.err_code
        if (err_code === 0) {
          window.alert('更改成功，即将跳转')
          // 服务端重定向针对异步请求无效
          window.location.href = '/'
        } else if (err_code === 500) {
          window.alert('服务器忙，请稍后重试！')
        } else if (err_code === 1) {
          window.alert('1')
        }
      }
    })
  })
</script>
{{/block}}